home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / wschesb1.zip / SRC / TIMECNT.C < prev    next >
C/C++ Source or Header  |  1994-03-16  |  6KB  |  205 lines

  1. /*
  2.   C source for Winsock Chess
  3.   
  4.   Revision 1994-03-15
  5.   Modified by Donald Munro for use as a 2 player chess game over a 
  6.   WINSOCK layer on a TCP (or other WinSock supporting) network.
  7.   Source code and make files for MS Visual C/C++ V1.00/1.50.
  8.   February/March 1994
  9.   All GNU copyright and distribution conditions as described below and in the
  10.   file COPYING also apply to WinSock Chess.
  11.   This module is adapted from GNU Chess.
  12.   
  13.   C source for GNU CHESS
  14.  
  15.   Revision: 1990-09-30
  16.  
  17.   Modified by Daryl Baker for use in MS WINDOWS environment
  18.  
  19.   This file is part of CHESS.
  20.  
  21.   CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  22.   WARRANTY.  No author or distributor accepts responsibility to anyone for
  23.   the consequences of using it or for whether it serves any particular
  24.   purpose or works at all, unless he says so in writing.  Refer to the CHESS
  25.   General Public License for full details.
  26.  
  27.   Everyone is granted permission to copy, modify and redistribute CHESS, but
  28.   only under the conditions described in the CHESS General Public License.
  29.   A copy of this license is supposed to have been given to you along with
  30.   CHESS so you can know your rights and responsibilities.  It should be in a
  31.   file named COPYING.  Among other things, the copyright notice and this
  32.   notice must be preserved on all copies.
  33. */
  34.  
  35. #define NOATOM 
  36. #define NOCLIPBOARD
  37. #define NOCREATESTRUCT
  38. #define NOFONT
  39. #define NOREGION
  40. #define NOSOUND
  41. #define NOWH
  42. #define NOWINOFFSETS
  43. #define NOCOMM
  44. #define NOKANJI
  45.  
  46. #include <windows.h>
  47. #include "timecnt.h"
  48. #include "chess.h"
  49.  
  50. extern int TCmoves, TCminutes, TCflag;
  51.  
  52. static int tmpTCmoves;
  53. static int tmpTCminutes;
  54.  
  55. /* Changed by DM - Used to use CheckRadioButton on non-contiguos control ids 
  56.    which causes intermittent protection faults and hangs (see Petzold plus
  57.    debug kernal output).
  58.    Changed timecnt.h to not use non-contiguos ids for the radio buttons and
  59.    added functions GetMoves and GetMinutes etc - there's probably a more 
  60.    elegant way of doing this but this was a quickfix. */
  61.  
  62. int GetMoves(WPARAM id)
  63. //---------------------
  64. { switch (id)
  65.    { case TMDLG_60MOV :
  66.         return 60;
  67.      case TMDLG_40MOV :
  68.         return 40;
  69.      case TMDLG_20MOV :
  70.         return 20;
  71.      case TMDLG_10MOV :
  72.         return 10;
  73.      case TMDLG_1MOV :
  74.         return 1;
  75.     }
  76.   return 40;
  77. }        
  78.         
  79. int GetMinutes(WPARAM id)
  80. //-----------------------
  81. { switch (id)
  82.    { case TMDLG_600MIN :
  83.         return 600;
  84.      case TMDLG_60MIN  :
  85.         return 60;
  86.      case TMDLG_30MIN  :
  87.         return 30;
  88.      case TMDLG_15MIN  :
  89.         return 15;    
  90.      case TMDLG_5MIN   :
  91.         return 5;
  92.     }
  93.   return 60;
  94. }        
  95.  
  96. int GetMinutesId(int nMinutes)
  97. //----------------------------
  98. { switch (nMinutes)
  99.    { case 600 :
  100.         return TMDLG_600MIN;
  101.      case 60 :
  102.         return TMDLG_60MIN;
  103.      case 30 :
  104.         return TMDLG_30MIN;
  105.      case 15 :
  106.         return TMDLG_15MIN;
  107.      case 5 :
  108.         return TMDLG_5MIN;
  109.     }
  110.   return TMDLG_60MIN;
  111. }        
  112.  
  113. int GetMovesId(int nMoves)
  114. //------------------------
  115. { switch (nMoves)
  116.    { case 60 :
  117.         return TMDLG_60MOV;
  118.      case 40 :
  119.         return TMDLG_40MOV;
  120.      case 20 :
  121.         return TMDLG_20MOV;
  122.      case 10 :
  123.         return TMDLG_10MOV;
  124.      case 1 :
  125.         return TMDLG_1MOV;
  126.     }
  127.   return TMDLG_40MOV;
  128. }        
  129.  
  130. BOOL CALLBACK TimeControlDlgProc ( HWND hDlg, UINT message,WPARAM wParam, 
  131.                                    LPARAM lParam)
  132. //-----------------------------------------------------------------------                                   
  133. {
  134.  
  135.    switch (message) {
  136.        case WM_INITDIALOG:     
  137.          tmpTCminutes = GetMinutesId(TCminutes);
  138.          tmpTCmoves   = GetMovesId(TCmoves);;
  139.          CheckRadioButton ( hDlg, TMDLG_1MOV, TMDLG_60MOV, tmpTCmoves);
  140.          CheckRadioButton ( hDlg, TMDLG_5MIN, TMDLG_600MIN, tmpTCminutes);
  141.          tmpTCminutes = TCminutes;
  142.          tmpTCmoves   = TCmoves;
  143.          return (TRUE);
  144.  
  145.       case WM_SYSCOMMAND:
  146.          if ( (wParam&0xfff0) == SC_CLOSE ) {
  147.               EndDialog(hDlg, NULL);
  148.               return TRUE;
  149.          }
  150.          break;
  151.  
  152.  
  153.        case WM_COMMAND:    
  154.          switch (wParam) {
  155.          
  156.             case IDOK:
  157.                TCminutes = tmpTCminutes;
  158.                TCmoves   = tmpTCmoves;
  159.                EndDialog(hDlg, 1);
  160.                return TRUE;
  161.                break;
  162.  
  163.              case IDCANCEL:
  164.               EndDialog(hDlg, NULL);
  165.               return TRUE;
  166.                break;
  167.  
  168.             case TMDLG_1MOV:
  169.             case TMDLG_10MOV:
  170.             case TMDLG_20MOV:
  171.             case TMDLG_40MOV:
  172.             case TMDLG_60MOV:
  173.                   // tmpTCmoves = wParam - TMDLG_MOV;       
  174.                   tmpTCmoves = GetMoves(wParam);
  175.                   CheckRadioButton ( hDlg, TMDLG_1MOV, TMDLG_60MOV, wParam);
  176.                   break;
  177.  
  178.             case TMDLG_5MIN:
  179.             case TMDLG_15MIN:
  180.             case TMDLG_30MIN:
  181.             case TMDLG_60MIN:
  182.             case TMDLG_600MIN:
  183.                   // tmpTCminutes = wParam - TMDLG_MIN;
  184.                   tmpTCminutes = GetMinutes(wParam);
  185.                   CheckRadioButton ( hDlg, TMDLG_5MIN, TMDLG_600MIN, wParam);
  186.                   break;
  187.          }
  188.           break;
  189.     }
  190.  
  191.     return (FALSE);               /* Didn't process a message    */
  192. }
  193.  
  194.  
  195. int TimeControlDialog ( HWND hWnd, HANDLE hInst, DWORD Param )
  196. { int status;
  197.  
  198.    status = DialogBoxParam (hInst,(LPCSTR)"TIMECNT",hWnd,
  199.                             TimeControlDlgProc, (LPARAM)Param);
  200.    return status;
  201. }
  202.  
  203.  
  204.  
  205.